# -*- coding: utf-8 -*-
# defined using shortcut keys
#  q h F p d s A t T U L W m D r l P B S R j a / z v i e f b E o x
# store all shortcut keys
menu = {"d": "database", "s": "session", "A": "asp", "t": "Table", "T": "Table_performance", "m": "Memory",
        "D": "dynamicsql", "U": "lock", "W": "wait_event", "r": "replication", "l": "database_list", "P": "sql_patch",
        "B": "slow_sql", "E": "redo", "o": "redo_time_count", "x": "xlog_redo_statics", "w": "wdr"}

page_menu = {
    "session": {"a": "details", "i": "dbmind", "f": "kill session", "←": "page left", "→": "page right"},
    "session_detail": {"f": "force", "e": "sql_explain", "c": "stack"},
    "asp": {"a": "query detail", "i": "dbmind", "←": "page left", "→": "page right"},
    "sql_explain": {"b": "back to session_detail"},
    "table": {"v": "table_detail", "←": "page left", "→": "page right"},
    "table_performance": {"v": "table_detail", "←": "page left", "→": "page right"},
    "table_detail": {"a": "table_index", },
    "table_index": {"b": "back to table_detail"},
    "memory": {"S": "sharemem", "R": "top_mem_used_session"},
    "top_mem_used_session": {"a": "session_detail"},
    "dynamicsql": {"a": "query detail", "i": "dbmind", "←": "page left", "→": "page right"},
    "lock": {"L": "lock_chain", "a": "session_detail", "f": "kill session", "←": "page left", "→": "page right"},
    "lock_chain": {"a": "session_detail", "f": "kill session", },
    "wait_event": {"j": "to session page,find event", },
    "replication": {"f": "drop slot"},
    "database_list": {"←": "page left", "→": "page right"},
    "sql_patch": {"a": "create patch", "f": "drop patch", "←": "page left", "→": "page right"},
    "slow_sql": {"a": "view query related", "i": "dbmind", "←": "page left", "→": "page right"},
    "redo": {"←": "page left", "→": "page right"},
    "redo_time_count": {"←": "page left", "→": "page right"},
    "wdr": {"a": "snap_summary_more_statement", "v": "WDR_ASH"},
    "snap_summary_more_statement": {"v": "snap_summary_statement", "M": "burr_analysis", "a": "rigorous_analysis",
                                    "←": "page left", "→": "page right"},
    "burr_analysis": {"v": "snap_summary_statement", "a": "rigorous_analysis"},
}
function_menu = {
    "database": {"h": "help", "q": "close", "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh",
                 "F": "freeze screen", "esc": "reset"},
    "session": {"a": "session_detail", "/": "search", "z": "sort by column by",
                "i": "dbmind_index_advise(only database sql is supported)", "f": "kill session", "←": "page left",
                "→": "page right",
                "h": "help", "q": "close", "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh",
                "F": "freeze screen", "esc": "reset"},
    "session_detail": {"f": "force", "e": "sql_explain", "c": "stack", "h": "help", "q": "close",
                       "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh", "F": "freeze screen",
                       "esc": "reset"},
    "asp": {"a": "view query detail", "/": "search", "z": "sort by column by",
            "i": "dbmind_index_advise(only database sql is supported)", "←": "page left",
            "→": "page right", "h": "help", "q": "close", "p": "snapshoot(f9 save f10 discard)",
            "space": "immediate refresh", "F": "freeze screen", "esc": "reset"},
    "sql_explain": {"b": "back to session_detail", "h": "help", "q": "close", "p": "snapshoot(f9 save f10 discard)",
                    "space": "immediate refresh", "F": "freeze screen", "esc": "reset"},
    "table": {"v": "table_detail", "/": "search", "z": "sort by column by",
              "←": "page left", "→": "page right", "h": "help", "q": "close",
              "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh", "F": "freeze screen",
              "esc": "reset"},
    "table_performance": {"v": "table_detail", "/": "search", "z": "sort by column by",
                          "←": "page left", "→": "page right", "h": "help", "q": "close",
                          "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh", "F": "freeze screen",
                          "esc": "reset"},
    "table_detail": {"a": "table_index", "h": "help", "q": "close", "p": "snapshoot(f9 save f10 discard)",
                     "space": "immediate refresh", "F": "freeze screen", "esc": "reset"},
    "table_index": {"b": "back to table_detail", "h": "help", "q": "close", "p": "snapshoot(f9 save f10 discard)",
                    "space": "immediate refresh", "F": "freeze screen", "esc": "reset"},
    "memory": {"S": "sharemem", "R": "top_mem_used_session", "h": "help", "q": "close",
               "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh", "F": "freeze screen",
               "esc": "reset"},
    "sharemem": {"/": "conditional filtration", "z": "sort by column by", "h": "help", "q": "close",
                 "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh", "F": "freeze screen",
                 "esc": "reset"},
    "top_mem_used_session": {"a": "session_detail", "/": "search", "z": "sort by column by",
                             "h": "help", "q": "close", "p": "snapshoot(f9 save f10 discard)",
                             "space": "immediate refresh", "F": "freeze screen", "esc": "reset"},
    "dynamicsql": {"a": "view query detail", "i": "dbmind_index_advise(only database sql is supported)",
                   "z": "sort by column by", "←": "page left",
                   "→": "page right", "h": "help", "q": "close", "p": "snapshoot(f9 save f10 discard)",
                   "space": "immediate refresh", "/": "search", "F": "freeze screen", "esc": "reset"},
    "lock": {"L": "lock_chain", "a": "session_detail", "/": "search", "z": "sort by column by",
             "f": "kill session", "←": "page left", "→": "page right", "h": "help", "q": "close",
             "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh", "F": "freeze screen", "esc": "reset"},
    "lock_chain": {"a": "session_detail", "z": "sort by column by", "f": "kill session",
                   "h": "help", "q": "close", "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh",
                   "F": "freeze screen", "esc": "reset"},
    "wait_event": {"/": "search", "z": "sort by column by",
                   "j": "go to the session page to find related data on wait_event or wait_status", "h": "help",
                   "q": "close", "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh",
                   "F": "freeze screen", "esc": "reset"},
    "replication": {"/": "search", "f": "drop slot", "h": "help", "q": "close",
                    "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh", "F": "freeze screen",
                    "esc": "reset"},
    "database_list": {"←": "page left", "→": "page right", "h": "help", "q": "close",
                      "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh",
                      "F": "freeze screen", "esc": "reset"},
    "sql_patch": {"a": "create patch", "f": "drop patch", "←": "page left", "→": "page right", "h": "help",
                  "q": "close", "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh",
                  "F": "freeze screen", "esc": "reset"},
    "slow_sql": {"a": "view query related", "/": "search", "z": "sort by column by",
                 "i": "dbmind_index_advise", "←": "page left", "→": "page right", "h": "help", "q": "close",
                 "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh", "F": "freeze screen",
                 "esc": "reset"},
    "redo": {"←": "page left", "→": "page right", "h": "help", "q": "close",
             "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh", "F": "freeze screen",
             "esc": "reset"},
    "redo_time_count": {"←": "page left", "→": "page right", "h": "help", "q": "close",
                        "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh", "F": "freeze screen",
                        "esc": "reset"},
    "xlog_redo_statics": {"←": "page left", "→": "page right", "h": "help", "q": "close",
                          "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh", "F": "freeze screen",
                          "esc": "reset"},
    "wdr": {"h": "help", "q": "close",
            "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh", "F": "freeze screen",
            "esc": "reset"},
    "snap_summary_more_statement": {"z": "sort by column by", "h": "help", "q": "close",
                                    "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh",
                                    "F": "freeze screen", "esc": "reset"},
    "burr_analysis": {"z": "sort by column by", "h": "help", "q": "close",
                      "p": "snapshoot(f9 save f10 discard)", "space": "immediate refresh",
                      "F": "freeze screen", "esc": "reset"},
    "rigorous_analysis": {"h": "help", "q": "close",
                          "space": "immediate refresh",
                          "F": "freeze screen", "esc": "reset"}
}

# page_field
background_data_field = {
    "database": ["active session/session", "blks_hit/(blks_hit+read)", "select_count/dml_count", "DATA_IO_TIME/DB_TIME",
                 "dynamic_used_memory/max_dynamic_memory", "busy_time/all_time", "start_date", "start_time",
                 "wal_status", "LocalRole", "ProcesMem", "Dynamic_Mem", "Shared_Mem", "Session", "Actsess", "Waiting",
                 "idleintran", "xact_commit", "xact_rollback", "totalcount", "ddl_count", "dml_count", "dcl_count",
                 "select_count", "update_count", "insert_count", "delete_count", "num_cpus", "num_cpu_cores",
                 "num_cpu_sockets", "blks_read", "blks_hit", "hitratio", "tup_fetched", "tup_inserted", "tup_update",
                 "tup_delete", "DB_TIME", "cpu_time", "execute_time", "data_io_time", "blk_read_time", "blk_write_time",
                 "redo_writetim", "temp_files", "temp_bytes", "conflicts", "deadlocks", "checkpoints",
                 "double_writes", "physical_memory_bytes", "idle_time", "user_time", "sys_time", "iowait_time",
                 "nice_time", "vm_page_in_bytes", "vm_page_out_bytes", "os_load_processes"],
    "session": ["active session/session", "n_commit", "n_blocks_fetched", "n_rollback", "n_local_blocks_read",
                "n_physical_read_operation", "n_sql", "n_sort_in_disk", "n_shared_blocks_dirtied", "n_table_scan",
                "n_cu_hdd_asyn_read", "n_local_blocks_dirtied", "n_shared_blocks_read", "n_blocks_read_time",
                "n_blocks_write_time", "n_sort_in_memory", "n_cu_mem_hit", "n_cu_hdd_sync_read", "pid", "query",
                "current_state", "xact_start_time", "query_start_time", "waiting", "wait_status", "wait_event",
                "db_time", "cpu_time", "execute_time", "data_io_time", "db_name", "user_name", "application_name",
                "client_addr"],
    "session_detail": ["query_id", "block_sessionid", "backend_start", "query_start", "datid", "datname", "usesysid",
                       "usename", "application_name", "client_addr", "client_hostname", "client_port",
                       "xact_start_time", "state_change_time", "waiting", "total_cpu_time", "db_time", "cpu_time",
                       "execution_time", "data_io_time", "parse_time", "plan_time", "rewrite_time", "net_send_time",
                       "pl_execution_time", "pl_compilation_time", "init_mem", "used_mem", "peak_mem", "wait_status",
                       "locktag", "lockmode", "query", 'n_commit', 'n_rollback', 'n_sql', 'n_table_scan',
                       'n_blocks_fetched', 'n_physical_read_operation', 'n_shared_blocks_dirtied',
                       'n_local_blocks_dirtied', 'n_shared_blocks_read', 'n_local_blocks_read', 'n_blocks_read_time',
                       'n_blocks_write_time', 'n_sort_in_memory', 'n_sort_in_disk', 'n_cu_mem_hit',
                       'n_cu_hdd_sync_read', 'n_cu_hdd_asyn_read'],
    "sql_explain": ["query", "advise", "explain"],
    "asp": ["datname", "username", "sessionid", "client_addr", "duration_ms", "event", "unique_query", "sample_time",
            "unique_query_id"],
    "table": ['datname', 'schemaname', 'relname', "relid", 'tabsize', 'idxsize', 'totalsize', "n_live_tup",
              "n_dead_tup", 'last_vacuum', 'last_autovacuum', 'last_analyze', 'last_autoanalyze', 'last_data_changed'],
    "table_performance": ['datname', 'schemaname', 'relname', "relid", 'seq_scan',
                          'seq_tup_read', 'idx_scan', 'idx_tup_fetch', 'n_tup_ins', 'n_tup_upd', 'n_tup_del',
                          'n_tup_hot_upd', 'heap_blks_read', 'heap_blks_hit', 'idx_blks_read', 'idx_blks_hit',
                          'toast_blks_read', 'toast_blks_hit', 'tidx_blks_read', 'tidx_blks_hit', 'phyrds', 'phywrts',
                          'phyblkrd', 'phyblkwrt', 'readtim'],
    "table_index": ["indexrelname", "relname", "schemaname", "datname", "idx_scan", "idx_tup_read", "idx_tup_fetch",
                    "idx_blks_hit", "phyrds", "phywrts", "phyblkrd", "phyblkwrt", "readtim", "writetim"],
    "table_detail": ["datname", "relid", "schemaname", "relname", "table_detail"],
    "lock": ["data_length", "pid", "locktype", "database", "relname", "page", "tuple", "transactionid", "virtualxid",
             "objid", "virtualtransaction", "mode", "granted", "fastpath", "locktag"],
    "lock_chain": ["blocker_holder", "lock_blocked_agent_id"],
    "wait_event": ["data_length", "nodename", "type", "event", "wait", "failed_wait", "total_wait_time",
                   "avg_wait_time", "history_max_wait_time", "history_min_wait_time", "last_updated"],
    "memory": ["process_memory_used_percent", "dynamic_memory_used_percent", "backend_memory_used_percent",
               "shared_memory_used_percent", "cstore_memory_used_percent", "sctpcomm_memory_used_percent",
               "gpu_dynamic_memory_used_percent", "target_ip", "max_process_memory", "process_used_memory",
               "max_dynamic_memory", "dynamic_used_memory", "dynamic_used_shrctx", "max_backend_memory",
               "backend_used_memory", "max_shared_memory", "shared_used_memory", "max_cstore_memory",
               "cstore_used_memory", "max_sctpcomm_memory", "sctpcomm_used_memory", "other_used_memory",
               "gpu_max_dynamic_memory", "gpu_dynamic_used_memory", "pooler_conn_memory", "pooler_freeconn_memory",
               "storage_compress_memory", "udf_reserved_memory"],
    'sharemem': ["data_length", "parent", "contextname", "level", "totalsize", "freesize", "usedsize",
                 "usedsize/totalsize"],
    "top_mem_used_session": ["data_length", "pid", "init_mem", "used_mem", "peak_mem", "query", "usename",
                             "client_addr"],
    "dynamicsql": ['data_length', 'unique_sql_id', 'query', 'user_name', 'data_io_time', 'avg_db_time', 'n_calls',
                   'db_time', 'cpu_time', 'execution_time', 'parse_time', 'plan_time',
                   'total_elapse_time', 'n_returned_rows', 'n_tuples_fetched', 'n_tuples_returned',
                   'n_tuples_inserted', 'n_tuples_updated', 'n_tuples_deleted', 'n_blocks_fetched', 'n_blocks_hit',
                   'n_soft_parse', 'n_hard_parse', 'rewrite_time', 'pl_execution_time', 'pl_compilation_time',
                   'net_send_info_time', 'net_send_info_n_calls', 'net_send_info_size', 'net_recv_info_time',
                   'net_recv_info_n_calls', 'net_recv_info_size', 'net_stream_send_info_time',
                   'net_stream_send_info_n_calls', 'net_stream_send_info_size', 'net_stream_recv_info_time',
                   'net_stream_recv_info_n_calls', 'net_stream_recv_info_size', 'sort_count',
                   'sort_time', 'sort_mem_used', 'sort_spill_count', 'sort_spill_size', 'hash_count', 'hash_time',
                   'hash_mem_used', 'hash_spill_count', 'hash_spill_size'],
    "replication": ["channel", "local_role", "peer_role", "peer_state", "sync_percent", "sync_state", "receive_gap",
                    "replay_gap", "sender_sent_location", "sender_write_location", "sender_flush_location",
                    "sender_replay_location", "receiver_received_location", "receiver_write_location",
                    "receiver_flush_location", "receiver_replay_location", 'slot_name', 'plugin', 'slot_type',
                    'datname', 'active', 'catalog_xmin', 'restart_lsn', 'diff_lsn', 'dummy_standby', 'confirmed_flush'],
    "index_recommendation": ["advised_indexes", "redundant_indexes"],
    "database_list": ["datname", "numbackends", "xact_commit", "xact_rollback", "blks_read",
                      "blks_hit", "tup_returned", "tup_fetched", "tup_inserted", "tup_updated",
                      "tup_deleted", "conflicts", "temp_files", "temp_bytes", "deadlocks", "blk_read_time",
                      "blk_write_time", "stats_reset"],
    "sql_patch": ["patch_name", "unique_sql_id", "username", "enable", "status", "abort",
                  "hint_string", "hint_node", "original_query", "original_query_tree",
                  "patched_query", "patched_query_tree", "description"],
    "slow_sql": ['session_id', 'query', 'unique_query_id', 'debug_query_id', 'duration_ms', 'db_name', 'user_name',
                 'application_name', 'client_addr', 'n_soft_parse', 'n_hard_parse', 'query_plan', 'n_returned_rows',
                 'n_tuples_fetched', 'n_tuples_returned', 'n_tuples_inserted', 'n_tuples_updated', 'n_tuples_deleted',
                 'n_blocks_fetched', 'n_blocks_hit', 'db_time', 'cpu_time', 'execution_time', 'data_io_time',
                 'parse_time', 'plan_time', 'rewrite_time', 'pl_execution_time', 'pl_compilation_time',
                 'net_send_info_time', 'net_send_info_n_calls', 'net_send_info_size', 'net_recv_info_time',
                 'net_recv_info_n_calls', 'net_recv_info_size', 'net_stream_send_info_time',
                 'net_stream_send_info_n_calls', 'net_stream_send_info_size', 'net_stream_recv_info_time',
                 'net_stream_recv_info_n_calls', 'net_stream_recv_info_size', 'lock_count', 'lock_time',
                 'lock_wait_count', 'lock_wait_time', 'lock_max_count', 'lwlock_count', 'lwlock_wait_count',
                 'lwlock_time', 'lwlock_wait_time', 'detail'],
    "redo": ['node_name', 'redo_start_ptr', 'redo_start_time', 'redo_done_time',
             'curr_time', 'min_recovery_point', 'read_ptr', 'last_replayed_read_ptr',
             'recovery_done_ptr', 'read_xlog_io_counter', 'read_xlog_io_total_dur',
             'read_data_io_counter', 'read_data_io_total_dur',
             'write_data_io_counter', 'write_data_io_total_dur',
             'process_pending_counter', 'process_pending_total_dur', 'apply_counter',
             'apply_total_dur', 'speed', 'local_max_ptr', 'primary_flush_ptr',
             'worker_info'],
    "redo_time_count": ['thread_name', 'step1_total', 'step1_count', 'step2_total',
                        'step2_count', 'step3_total', 'step3_count', 'step4_total',
                        'step4_count', 'step5_total', 'step5_count', 'step6_total',
                        'step6_count', 'step7_total', 'step7_count', 'step8_total',
                        'step8_count', 'step9_total', 'step9_count'
                        ],
    "xlog_redo_statics": ['xlog_type', 'rmid', 'info', 'num', 'extra'],
    "wdr": ["snapshot_id", "start_ts", "end_ts"],
    "snap_summary_more_statement": ['snapshot_id', 'snap_user_name', 'snap_unique_sql_id', 'snap_node_name',
                                    'snap_node_id',
                                    'snap_user_id', 'snap_query', 'n_calls', 'total_elapse_time', 'n_returned_rows',
                                    'n_tuples_fetched', 'n_tuples_returned', 'n_tuples_inserted', 'n_tuples_updated',
                                    'n_tuples_deleted', 'n_blocks_fetched', 'n_blocks_hit', 'n_soft_parse',
                                    'n_hard_parse', 'db_time', 'cpu_time', 'execution_time', 'parse_time', 'plan_time',
                                    'rewrite_time', 'pl_execution_time', 'pl_compilation_time',
                                    'snap_net_send_info_time', 'snap_net_send_info_n_calls', 'snap_net_send_info_size',
                                    'snap_net_recv_info_time', 'snap_net_recv_info_n_calls', 'snap_net_recv_info_size',
                                    'snap_net_stream_send_info_time', 'snap_net_stream_send_info_n_calls',
                                    'snap_net_stream_send_info_size', 'snap_net_stream_recv_info_time',
                                    'snap_net_stream_recv_info_info_n_calls', 'snap_net_stream_recv_info_size',
                                    'snap_last_updated', 'sort_count', 'sort_time', 'sort_mem_used',
                                    'sort_spill_count', 'sort_spill_size', 'hash_count', 'hash_time', 'hash_mem_used',
                                    'hash_spill_count', 'hash_spill_size'],
    "burr_analysis": ['snapshot_id', 'snap_unique_sql_id', 'snap_user_name',
                      'avg_execution_time', 'std_avg_execution_time', 'readline', 'max_avg_execution_time',
                      'snap_query'],
    "snap_summary_statement": ['snapshot_id', 'snap_node_name', 'snap_node_id',
                               'snap_user_name', 'snap_user_id',
                               'snap_unique_sql_id', 'snap_n_calls',
                               'snap_min_elapse_time', 'snap_max_elapse_time',
                               'snap_total_elapse_time', 'snap_n_returned_rows',
                               'snap_n_tuples_fetched', 'snap_n_tuples_returned',
                               'snap_n_tuples_inserted', 'snap_n_tuples_updated',
                               'snap_n_tuples_deleted', 'snap_n_blocks_fetched',
                               'snap_n_blocks_hit', 'snap_n_soft_parse',
                               'snap_n_hard_parse', 'snap_db_time', 'snap_cpu_time',
                               'snap_execution_time', 'snap_parse_time',
                               'snap_plan_time', 'snap_rewrite_time',
                               'snap_pl_execution_time', 'snap_pl_compilation_time',
                               'snap_data_io_time',
                               "snap_net_send_info_time",
                               "snap_net_send_info_n_calls",
                               "snap_net_send_info_size", "snap_net_recv_info_time",
                               "snap_net_recv_info_n_calls",
                               "snap_net_recv_info_size",
                               "snap_net_stream_send_info_time",
                               "snap_net_stream_send_info_n_calls",
                               "snap_net_stream_send_info_size",
                               "snap_net_stream_recv_info_time",
                               "snap_net_stream_recv_info_info_n_calls",
                               "snap_net_stream_recv_info_size",
                               'snap_last_updated',
                               'snap_sort_count', 'snap_sort_time',
                               'snap_sort_mem_used', 'snap_sort_spill_count',
                               'snap_sort_spill_size', 'snap_hash_count',
                               'snap_hash_time', 'snap_hash_mem_used',
                               'snap_hash_spill_count', 'snap_hash_spill_size', 'snap_query']

}
display_field = {
    "database": ["active session/session", "blks_hit/(blks_hit+read)", "select_count/dml_count", "DATA_IO_TIME/DB_TIME",
                 "dynamic_used_memory/max_dynamic_memory", "busy_time/all_time", "start_date", "start_time",
                 "wal_status", "LocalRole", "ProcesMem", "Dynamic_Mem", "Shared_Mem", "Session", "Actsess", "Waiting",
                 "idleintran", "xact_commit", "xact_rollback", "totalcount", "ddl_count", "dml_count", "dcl_count",
                 "select_count", "update_count", "insert_count", "delete_count", "num_cpus", "num_cpu_cores",
                 "num_cpu_sockets", "blks_read", "blks_hit", "hitratio", "tup_fetched", "tup_inserted", "tup_update",
                 "tup_delete", "DB_TIME(s)", "cpu_time(s)", "execute_time(s)", "data_io_time(s)", "blk_read_time",
                 "blk_write_time", "redo_writetim", "temp_files", "temp_bytes", "conflicts", "deadlocks", "checkpoints",
                 "double_writes", "physical_memory_bytes", "idle_time", "user_time", "sys_time",
                 "iowait_time", "nice_time", "vm_page_in_bytes", "vm_page_out_bytes", "os_load_processes"],
    "session": ["active session/session", "n_commit", "n_blocks_fetched", "n_rollback", "n_local_blocks_read",
                "n_physical_read_operation", "n_sql", "n_sort_in_disk", "n_shared_blocks_dirtied", "n_table_scan",
                "n_cu_hdd_asyn_read", "n_local_blocks_dirtied", "n_shared_blocks_read", "n_blocks_read_time",
                "n_blocks_write_time", "n_sort_in_memory", "n_cu_mem_hit", "n_cu_hdd_sync_read", "pid", "query",
                "current_state", "xact_start_time(ms)", "query_start_time(ms)", "waiting", "wait_status", "wait_event",
                "db_time(s)", "cpu_time(s)", "execute_time(s)", "data_io_time(s)", "db_name", "user_name",
                "application_name", "client_addr"],
    "session_detail": ["query_id", "block_sessionid", "backend_start", "query_start", "datid", "datname", "usesysid",
                       "usename", "application_name", "client_addr", "client_hostname", "client_port",
                       "xact_start_time", "state_change_time", "waiting", "total_cpu_time", "db_time(ms)",
                       "cpu_time(ms)", "execution_time(ms)", "data_io_time(ms)", "parse_time(ms)", "plan_time(ms)",
                       "rewrite_time(ms)", "net_send_time(ms)", "pl_execution_time(ms)", "pl_compilation_time(ms)",
                       "init_mem", "used_mem", "peak_mem", "wait_status", "locktag", "lockmode", "query", 'n_commit',
                       'n_rollback', 'n_sql', 'n_table_scan', 'n_blocks_fetched', 'n_physical_read_operation',
                       'n_shared_blocks_dirtied', 'n_local_blocks_dirtied', 'n_shared_blocks_read',
                       'n_local_blocks_read', 'n_blocks_read_time', 'n_blocks_write_time', 'n_sort_in_memory',
                       'n_sort_in_disk', 'n_cu_mem_hit', 'n_cu_hdd_sync_read', 'n_cu_hdd_asyn_read', ],
    "sql_explain": ["query", "advise", "explain"],
    "asp": ["datname", "username", "sessionid", "client_addr", "duration_ms", "event", "unique_query", "sample_time",
            "unique_query_id"],
    "table": ['datname', 'schemaname', 'relname', "relid", "tabsize/MB", "idxsize/MB", "totalsize/MB", 'last_vacuum',
              'last_autovacuum', 'last_analyze', 'last_autoanalyze', 'last_data_changed'],
    "table_performance": ['datname', 'schemaname', 'relname', "relid", 'seq_scan',
                          'seq_tup_read', 'idx_scan', 'idx_tup_fetch', 'n_tup_ins', 'n_tup_upd', 'n_tup_del',
                          'n_tup_hot_upd', 'heap_blks_read', 'heap_blks_hit', 'idx_blks_read', 'idx_blks_hit',
                          'toast_blks_read', 'toast_blks_hit', 'tidx_blks_read', 'tidx_blks_hit', 'phyrds', 'phywrts',
                          'phyblkrd', 'phyblkwrt', 'readtim'],
    "table_index": ["indexrelname", "relname", "schemaname", "datname", "idx_scan", "idx_tup_read", "idx_tup_fetch",
                    "idx_blks_hit", "phyrds", "phywrts", "phyblkrd", "phyblkwrt", "readtim", "writetim"],
    "table_detail": ["datname", "relid", "schemaname", "relname", "table_detail"],
    "lock": ["data_length", "pid", "locktype", "database", "relname", "page", "tuple", "transactionid", "virtualxid",
             "objid", "virtualtransaction", "mode", "granted", "fastpath", "locktag"],
    "lock_chain": ["blocker_holder", "lock_blocked_agent_id"],
    "wait_event": ["data_length", "nodename", "type", "event", "wait", "failed_wait", "total_wait_time(ms)",
                   "avg_wait_time(ms)", "history_max_wait_time(ms)", "history_min_wait_time(ms)", "last_updated"],
    "memory": ["process_memory_used_percent", "dynamic_memory_used_percent", "backend_memory_used_percent",
               "shared_memory_used_percent", "cstore_memory_used_percent", "sctpcomm_memory_used_percent",
               "gpu_dynamic_memory_used_percent", "target_ip", "max_process_memory", "process_used_memory",
               "max_dynamic_memory", "dynamic_used_memory", "dynamic_used_shrctx", "max_backend_memory",
               "backend_used_memory", "max_shared_memory", "shared_used_memory", "max_cstore_memory",
               "cstore_used_memory", "max_sctpcomm_memory", "sctpcomm_used_memory", "other_used_memory",
               "gpu_max_dynamic_memory", "gpu_dynamic_used_memory", "pooler_conn_memory", "pooler_freeconn_memory",
               "storage_compress_memory", "udf_reserved_memory"],
    'sharemem': ["data_length", "parent", "contextname", "level", "totalsize", "freesize", "usedsize",
                 "usedsize/totalsize"],
    "top_mem_used_session": ["data_length", "pid", "init_mem", "used_mem", "peak_mem", "query", "usename",
                             "client_addr"],
    "dynamicsql": ['data_length', 'unique_sql_id', 'query', 'user_name', 'data_io_time(s)', 'avg_db_time(s)', 'n_calls',
                   'db_time(s)', 'cpu_time(s)', 'execution_time(s)', 'parse_time(s)', 'plan_time(s)',
                   'total_elapse_time', 'n_returned_rows', 'n_tuples_fetched', 'n_tuples_returned',
                   'n_tuples_inserted', 'n_tuples_updated', 'n_tuples_deleted', 'n_blocks_fetched', 'n_blocks_hit',
                   'n_soft_parse', 'n_hard_parse', 'rewrite_time(s)', 'pl_execution_time(s)', 'pl_compilation_time(s)',
                   'net_send_info_time(s)', 'net_send_info_n_calls', 'net_send_info_size', 'net_recv_info_time(s)',
                   'net_recv_info_n_calls', 'net_recv_info_size', 'net_stream_send_info_time(s)',
                   'net_stream_send_info_n_calls', 'net_stream_send_info_size', 'net_stream_recv_info_time(s)',
                   'net_stream_recv_info_n_calls', 'net_stream_recv_info_size', 'sort_count',
                   'sort_time(s)', 'sort_mem_used', 'sort_spill_count', 'sort_spill_size', 'hash_count', 'hash_time(s)',
                   'hash_mem_used', 'hash_spill_count', 'hash_spill_size'],
    "replication": ["channel", "local_role", "peer_role", "peer_state", "sync_percent", "sync_state", "receive_gap(kb)",
                    "replay_gap(kb)", "sender_sent_location(kb/s)", "sender_write_location(kb/s)",
                    "sender_flush_location(kb/s)", "sender_replay_location(kb/s)", "receiver_received_location(kb/s)",
                    "receiver_write_location(kb/s)", "receiver_flush_location(kb/s)", "receiver_replay_location(kb/s)",
                    'slot_name', 'plugin', 'slot_type', 'datname', 'active', 'catalog_xmin', 'restart_lsn', 'diff_lsn',
                    'dummy_standby', 'confirmed_flush'],
    "index_recommendation": ["advised_indexes"],
    "database_list": ["datname", "numbackends", "xact_commit", "xact_rollback", "blks_read",
                      "blks_hit", "tup_returned", "tup_fetched", "tup_inserted", "tup_updated",
                      "tup_deleted", "conflicts", "temp_files", "temp_bytes", "deadlocks", "blk_read_time",
                      "blk_write_time", "stats_reset"],
    "sql_patch": ["patch_name", "unique_sql_id", "username", "enable", "status", "abort", "hint_string", "hint_node",
                  "original_query", "original_query_tree", "patched_query", "patched_query_tree", "description"],
    "slow_sql": ['session_id', 'query', 'unique_query_id', 'debug_query_id', 'duration_ms', 'db_name', 'user_name',
                 'application_name', 'client_addr', 'n_soft_parse', 'n_hard_parse', 'query_plan', 'n_returned_rows',
                 'n_tuples_fetched', 'n_tuples_returned', 'n_tuples_inserted', 'n_tuples_updated', 'n_tuples_deleted',
                 'n_blocks_fetched', 'n_blocks_hit', 'db_time(s)', 'cpu_time(s)', 'execution_time(s)',
                 'data_io_time(s)', 'parse_time', 'plan_time', 'rewrite_time', 'pl_execution_time',
                 'pl_compilation_time', 'net_send_info_time(s)', 'net_send_info_n_calls', 'net_send_info_size',
                 'net_recv_info_time(s)', 'net_recv_info_n_calls', 'net_recv_info_size', 'net_stream_send_info_time(s)',
                 'net_stream_send_info_n_calls', 'net_stream_send_info_size', 'net_stream_recv_info_time(s)',
                 'net_stream_recv_info_n_calls', 'net_stream_recv_info_size', 'lock_count', 'lock_time',
                 'lock_wait_count', 'lock_wait_time', 'lock_max_count', 'lwlock_count', 'lwlock_wait_count',
                 'lwlock_time', 'lwlock_wait_time', 'detail'],
    "redo": ['node_name', 'redo_start_ptr', 'redo_start_time', 'redo_done_time',
             'curr_time', 'min_recovery_point', 'read_ptr', 'last_replayed_read_ptr',
             'recovery_done_ptr', 'read_xlog_io_counter', 'read_xlog_io_total_dur',
             'read_data_io_counter', 'read_data_io_total_dur',
             'write_data_io_counter', 'write_data_io_total_dur',
             'process_pending_counter', 'process_pending_total_dur', 'apply_counter',
             'apply_total_dur', 'speed', 'local_max_ptr', 'primary_flush_ptr',
             'worker_info'],
    "redo_time_count": ['thread_name', 'step1_total', 'step1_count', 'step2_total',
                        'step2_count', 'step3_total', 'step3_count', 'step4_total',
                        'step4_count', 'step5_total', 'step5_count', 'step6_total',
                        'step6_count', 'step7_total', 'step7_count', 'step8_total',
                        'step8_count', 'step9_total', 'step9_count'
                        ],
    "xlog_redo_statics": ['xlog_type', 'rmid', 'info', 'num', 'extra'],
    "wdr": ["snapshot_id", "start_ts", "end_ts"],
    "snap_summary_more_statement": ['snapshot_id', 'snap_user_name', 'snap_unique_sql_id', 'snap_node_name',
                                    'snap_node_id',
                                    'snap_user_id', 'snap_query', 'n_calls', 'total_elapse_time', 'n_returned_rows',
                                    'n_tuples_fetched', 'n_tuples_returned', 'n_tuples_inserted', 'n_tuples_updated',
                                    'n_tuples_deleted', 'n_blocks_fetched', 'n_blocks_hit', 'n_soft_parse',
                                    'n_hard_parse', 'db_time', 'cpu_time', 'execution_time', 'parse_time', 'plan_time',
                                    'rewrite_time', 'pl_execution_time', 'pl_compilation_time',
                                    'snap_net_send_info_time', 'snap_net_send_info_n_calls', 'snap_net_send_info_size',
                                    'snap_net_recv_info_time', 'snap_net_recv_info_n_calls', 'snap_net_recv_info_size',
                                    'snap_net_stream_send_info_time', 'snap_net_stream_send_info_n_calls',
                                    'snap_net_stream_send_info_size', 'snap_net_stream_recv_info_time',
                                    'snap_net_stream_recv_info_info_n_calls', 'snap_net_stream_recv_info_size',
                                    'snap_last_updated', 'sort_count', 'sort_time', 'sort_mem_used',
                                    'sort_spill_count', 'sort_spill_size', 'hash_count', 'hash_time', 'hash_mem_used',
                                    'hash_spill_count', 'hash_spill_size'],
    "burr_analysis": ['snapshot_id', 'snap_unique_sql_id', 'snap_user_name',
                      'avg_execution_time', 'std_avg_execution_time', 'readline', 'max_avg_execution_time',
                      'snap_query'],
    "snap_summary_statement": ['snapshot_id', 'snap_node_name', 'snap_node_id',
                               'snap_user_name', 'snap_user_id',
                               'snap_unique_sql_id', 'snap_n_calls',
                               'snap_min_elapse_time', 'snap_max_elapse_time',
                               'snap_total_elapse_time', 'snap_n_returned_rows',
                               'snap_n_tuples_fetched', 'snap_n_tuples_returned',
                               'snap_n_tuples_inserted', 'snap_n_tuples_updated',
                               'snap_n_tuples_deleted', 'snap_n_blocks_fetched',
                               'snap_n_blocks_hit', 'snap_n_soft_parse',
                               'snap_n_hard_parse', 'snap_db_time', 'snap_cpu_time',
                               'snap_execution_time', 'snap_parse_time',
                               'snap_plan_time', 'snap_rewrite_time',
                               'snap_pl_execution_time', 'snap_pl_compilation_time',
                               'snap_data_io_time',
                               "snap_net_send_info_time",
                               "snap_net_send_info_n_calls",
                               "snap_net_send_info_size", "snap_net_recv_info_time",
                               "snap_net_recv_info_n_calls",
                               "snap_net_recv_info_size",
                               "snap_net_stream_send_info_time",
                               "snap_net_stream_send_info_n_calls",
                               "snap_net_stream_send_info_size",
                               "snap_net_stream_recv_info_time",
                               "snap_net_stream_recv_info_info_n_calls",
                               "snap_net_stream_recv_info_size",
                               'snap_last_updated',
                               'snap_sort_count', 'snap_sort_time',
                               'snap_sort_mem_used', 'snap_sort_spill_count',
                               'snap_sort_spill_size', 'snap_hash_count',
                               'snap_hash_time', 'snap_hash_mem_used',
                               'snap_hash_spill_count', 'snap_hash_spill_size', 'snap_query']
}

help_tip = """ogtop is an openGauss interactive monitor terminal.

Usage:
    omm local login usage:
        ogtop -p[port] -d[database]
    other usage:
        ogtop -h[host] -p[port] -d[database] -u[user]

General options:
    -v, --version 	output version information, then exit
    -?, --help          show this help, then exit

Connection options:
    -h, --host 		ip address of target database server
    -p, --port 		target database port
    -d, --database      target database
    -u, --user 		login user
    -W, --password      the password of specified database user

Function options:
    d                   database: Displays the overall resource utilization of the database, such as running status,session,statistics,memory,load,etc
    s                   session:  Displays session-related information in the current instance, including all sessions, and also supports viewing the details of a single session.
    A                   asp: Displays the historical active session information within a certain period of time
    t                   table:  Displays the status information of tables in the connected database in the current database,such as size,last_vacuum,etc
    T                   table_performance: table_performance: Display table performance-related statistics, supports viewing the definition of a single table and its index statistics
    U                   lock: Displays all lock information in the current instance, such as waiting for lock transactions, lock types, lock objects, etc
    m                   memory: Displays the overall memory usage of the database, such as the memory used by processes, maximum dynamic memory, and shared memory, etc
    D                   dynamicsql: Displays performance information about the execution of SQL statements, such as execution time, etc
    W                   wait_event: Displays performance information about wait events, such as wait event type, wait count, and wait time, etc
    r                   replication: Displays stream replication status and replication_slot information 
    P                   sql_patch: Supports creating abort sql patch to avoid early error reporting for specific statements, and also supports viewing and deleting patches.
    B                   slow_sql: Displays the slow SQL information recorded by the database within a certain period of time
    E                   redo: collect statistics on local redo logs
    o                   redo_time_count: collect statistics about the operation time in redo logs of the local node
    x                   xlog_redo_statics: collect statistics on all types of logs that have been played back by the local node
    w                   wdr: view performance reports of the database at different points in time

General function:
    h                   The internal help documents of the tool facilitate users to use additional functions
    q                   Exit ogtop and end the process
    space               refresh the page
    F                   Freeze the screen to retain data
    p                   Page snapshot to save text data

Function extension:
    session-->session_detail-->sql_explain                                                                                                                            
    session-->index_recommendation                                                                                                                                          
    table-->table_detail-->table_index                                                                                                                                      
    table_performance-->table_detail-->table_index                                                                                                                          
    lock-->session_detail                                                                                                                                                   
    -->lock_chain-->session_detail                                                                                                                                      
    memory-->sharemem&top_mem_used_session                                                                                                                                 
    -->top_mem_used_session-->session_detail                                                                                                                          
    dynamicsql-->index_recommendation  
    wdr-->snap_summary_more_statement-->snap_summary_statement&burr_analysis&rigorous_analysis
    -->burr_analysis-->snap_summary_statement&rigorous_analysis
    -->rigorous_analysis-->snap_summary_statement
    
    
    """
version_tip = """OgTop 2.0 compiled at 2024-06-11 09:00:00 commit 0 last mr"""
